package com.AdvancedDemos.LearnVariousAPI.时间日期类.传统时间日期类;

import java.util.Date;

public class LearnDate {
    public static void main(String[] args) {
        //JDK7提供util包中的时间日期类Date(了解)
        //Date()对象是当前系统的时间日期

        //1.无参构造
        System.out.println("-------------");
        Date date = new Date();
        System.out.println(date);//Sun Mar 05 09:44:10 CST 2023

        //2.拿到时间毫秒值
        System.out.println("-------------");
        System.out.println(date.getTime()/*Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT*/);


        //3.有参构造,把时间毫秒值转换成Data对象
        System.out.println("-------------");
        Date date1 = new Date(date.getTime() + 2000L);//两秒后的日期
        System.out.println(date1);

        System.out.println("-------------");
        date = new Date(0L);
        System.out.println(date);//Thu Jan 01 08:00:00 CST 1970
        date = new Date(Long.MAX_VALUE);
        System.out.println(date);   //Sun Aug 17 15:12:55 CST 292278994


        //4.直接把日期对象的时间通过setTime方法进行修改
        System.out.println("-------------");
        date.setTime(date1.getTime());//Sets this {@code Date} object to represent a point in time that is* {@code time} milliseconds after January 1, 1970 00:00:00 GMT.
        System.out.println(date);
        date.setTime(1000L);
        System.out.println(date);

        System.out.println("-------------");
        System.out.println(new Date(0).before(new Date(1)));
        System.out.println(new Date(0).after(new Date(1)));
        System.out.println(new Date(1).equals(new Date(1)));

    }
}
